﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Media;

namespace VKontakteClient
{
    /// <summary>
    /// Конвертер преобразующий описание сообщения уведомления в элементы UI
    /// </summary>
    class MessageToUIConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is Message)) return null;
            var message = (Message)value;
            string result = message.Human.ToString() + " изменил ";
            foreach (var v in message.Properties) result += v + ",";
            result = result.Remove(result.Length - 1) + ".";
            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    /// <summary>
    /// Конвертер для подсветки кнопок, которые пересылают на реализованные контролы, на главном окне
    /// </summary>
    class ButtonTextToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return null;
            var text = value.ToString();
            if (VKontakteAPI.MadeOwn.Select(v => v.Text).Contains(text))
            {
                if (VKontakteAPI.MadeOwn.Where(v => App.Settings.CoreModePages.Contains(v.Url)).Select(v => v.Text).Contains(text))
                    return new LinearGradientBrush(Colors.LightGray, Colors.LightCyan, 90);
                return new LinearGradientBrush(Colors.White, Colors.DarkCyan, 90);
            }
            return new SolidColorBrush(Colors.LightGray);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    /// <summary>
    /// Конвертер для скрытия строк в профиле с пустыми значениями
    /// </summary>
    class IsNullToIntConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null) return 0;
            if (value is string && (string.IsNullOrEmpty(value as string))) return 0;
            if (value is DateTime && value.Equals(DateTime.MinValue)) return 0;
            return double.NaN;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    /// <summary>
    /// Класс преобразования булевого типа в видимость.
    /// </summary>
    class VisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            Visibility v;
            if ((bool)value == true) v = Visibility.Visible;
            else v = Visibility.Collapsed;
            return v;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    /// <summary>
    /// Класс преобразования класса пола человека в осмысленный текст для байндингов
    /// </summary>
    class GenderConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is Gender)) return null;
            var X = (Gender)value;
            if (X == Gender.Male) return "мужской";
            if (X == Gender.Female) return "женский";
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    /// <summary>
    /// Класс преобразования даты в осмысленный текст для байндингов
    /// </summary>
    class DateConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is DateTime)) return null;
            var d = (DateTime)value;
            return (d.Day<10?"0":"") + d.Day + "." + (d.Month<10?"0":"") + d.Month + "." + d.Year;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    /// <summary>
    /// Класс преобразования даты и времени в осмысленный текст для байндингов
    /// </summary>
    class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is DateTime)) return null;
            var d = (DateTime)value;
            return (d.Hour < 10 ? "0" : "") + d.Hour + ":" + (d.Minute < 10 ? "0" : "") + d.Minute + ":" + (d.Second < 10 ? "0" : "") + d.Second + " " + (d.Day < 10 ? "0" : "") + d.Day + "." + (d.Month < 10 ? "0" : "") + d.Month + "." + d.Year;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    /// <summary>
    /// Класс преобразования класса отношений в осмысленный текст для байндингов
    /// </summary>
    class RelationConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(values[0] is Relation)) return null;
            if (!(values[1] is Gender)) return null;
            var relation = values[0] as Relation;
            var gender = (Gender)values[1];
            return relation.ToString(gender);
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
